package com.jeecg.p3.system.poster.service;


import com.jeecg.p3.system.poster.dao.AdvisorCouponDao;
import com.jeecg.p3.system.poster.dao.ProductCouponDao;
import com.jeecg.p3.system.poster.entity.AdvisorCoupon;
import com.jeecg.p3.system.poster.entity.ProductCoupon;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @ClassName: ProductCouponService
 * @Description: TODO 顾问优惠券关联处理层
 * @author: zhangxiao
 * @date: 2020年11月30日 下午7:29:38
 */
@Service
public class AdvisorCouponService {
    @Resource
    private AdvisorCouponDao dao;

    /**
     * 分页查询顾问优惠券
     * @param pageQuery
     * @return
     */
    public PageList<AdvisorCoupon> queryPageList(PageQuery<AdvisorCoupon> pageQuery) {
        PageList<AdvisorCoupon> result = new PageList<AdvisorCoupon>();
        Integer itemCount = dao.count(pageQuery);
        PageQueryWrapper<AdvisorCoupon> wrapper = new PageQueryWrapper<AdvisorCoupon>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<AdvisorCoupon> list = dao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据传参获取顾问优惠券数量
     * @param coupon
     * @return
     */
    public Integer count(AdvisorCoupon coupon) {
        PageQuery<AdvisorCoupon> pageQuery = new PageQuery<>();
        pageQuery.setQuery(coupon);
        return dao.count(pageQuery);
    }

    /**
     * 新增顾问优惠券信息
     * @param coupon
     */
    public void doAdd(AdvisorCoupon coupon) {
        dao.insert(coupon);
    }

    /**
     * 根据id查询顾问优惠券信息
     * @param id
     * @return
     */
    public AdvisorCoupon findById(Long id) {
        return dao.get(id);
    }

    /**
     * 根据传参获取顾问优惠券列表信息
     * @param coupon
     * @return
     */
    public List<AdvisorCoupon> findByParam(AdvisorCoupon coupon) {
        return dao.findByParam(coupon);
    }

    /**
     * 根据参数获取唯一的顾问优惠券信息
     * @param coupon
     * @return
     */
    public AdvisorCoupon findByParams(AdvisorCoupon coupon) {
        List<AdvisorCoupon> advisorCoupons = dao.findByParam(coupon);
        if(advisorCoupons != null && advisorCoupons.size() > 0) {
            return advisorCoupons.get(0);
        } else {
            return null;
        }
    }
    /**
     * 编辑顾问优惠券信息
     * @param coupon
     */
    public void doEdit(AdvisorCoupon coupon) {
        dao.update(coupon);
    }

    /**
     * 删除顾问优惠券信息
     * @param coupon
     */
    public void doDelete(AdvisorCoupon coupon) {
        coupon.setStatus("0");
        dao.update(coupon);
    }
}
